Skip to content

Conversation

@ZODIAC3K
Copy link
Contributor

@ZODIAC3K ZODIAC3K commented Nov 10, 2025

Issue: #1128

Matugen was returning color objects with mode-based properties ({dark, default, light}) instead of hex strings when using --json hex flag. The getMatugenHex() function expected hex strings but received objects, causing errors like:

[Matugen] Invalid color properties (not hex colors): background (value: [object Object]), ...

The function getMatugenVariations() tried to access properties like matugenColors.primary expecting a hex string, but got an object instead.

Solution

Added destructuring logic in generateMatugenColors() to extract hex values from mode-based color objects:

  • Extracts the correct color based on the selected mode (dark or light)
  • Falls back to default if mode-specific color is not available
  • Handles edge cases (direct hex property, RGB values)
  • Added comprehensive comments documenting the structure transformation

Changes

src/services/matugen/index.ts

  • Added color object destructuring logic to extract hex values based on mode
  • Added detailed comments documenting the structure before/after destructuring
  • Removed excessive validation code
  • Added comment in getMatugenHex() clarifying it expects destructured hex strings

env.d.ts

  • Added TypeScript declaration for GIF file imports (*.gif)

src/style/optionsTrackers.ts

  • Fixed TypeScript error for connect() method on WallpaperService by adding type assertion to GObject.Object

.gitignore

  • Added pnpm-lock.yaml to ignore list

Testing

  • ✅ Matugen colors are correctly extracted from mode-based objects
  • ✅ Bar colors update correctly when wallpaper changes
  • ✅ Matugen works for both dark and light modes

Example

Before (what matugen returns):

{
    "colors": {
        "primary": { "dark": "#4dd0a6", "default": "#4dd0a6", "light": "#006c4c" },
        "background": { "dark": "#0f1512", "default": "#0f1512", "light": "#f5fbf6" }
    }
}

After (what we pass to getMatugenHex):

{
    "primary": "#4dd0a6", // extracted from obj[mode] or obj.default
    "background": "#0f1512"
}

…nd path normalization

- Added normalization of wallpaper paths to ensure valid image files are processed.
- Improved error messages and notifications for better user feedback when Matugen is disabled or when errors occur during color generation.
- Updated the color mapping logic to handle different color formats and ensure only hex strings are returned.
- Updated the connection method for wallpaperService to ensure it is treated as a GObject.Object, enhancing type safety and preventing potential runtime errors.
- Streamlined the process of extracting hex values from mode-based color objects by removing redundant checks and directly using the mode or default values.
- Improved code readability and maintainability while ensuring consistent handling of color formats.
@crocodilestick
Copy link

Can confirm this works great with matugen v3 but I edited this section to make it backwards compatible:

            // Extract hex values from mode-based color objects
            // Matugen v3 returns objects with {dark, default, light} structure
            // Matugen v2 returns simple hex strings
            const processedColors: Record<string, string> = {};
            for (const [key, value] of Object.entries(colors)) {
                if (typeof value === 'string') {
                    // Handle Matugen v2 (direct string value)
                    processedColors[key] = value;
                } else {
                    // Handle Matugen v3 (object with mode variants)
                    const obj = value as Record<string, string>;
                    processedColors[key] = obj[mode] ?? obj.default;
                }
            }
            colors = processedColors;

@regit
Copy link

regit commented Jan 5, 2026

Hello, I'm really enjoying hyprpanel but I'm waiting for this integration with Matugen to work. Is there anything I can do to help ?

@Jas-SinghFSU Jas-SinghFSU merged commit a494780 into Jas-SinghFSU:master Jan 7, 2026
1 check passed
@Jas-SinghFSU
Copy link
Owner

Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants